package com.ruoyi.web.service.pay;

import lombok.extern.slf4j.Slf4j;

import java.io.InputStream;
import java.util.Properties;

@Slf4j
public class PayConfigUtils {

    /**
     * 微信证书模式支付参数
     */
    public static String appid; //微信appiid
    public static String mch_id;//微信商户id
    public static String notify_url;//微信支付回调地址
    public static String check_name;//微信提现是否强制实名
    public static String api_key;//微信支付接口秘钥
    public static String cert_path;//微信提现证书路径

    /**
     * 支付宝证书模式支付参数
     */
    public static String al_appid;//支付宝appid
    public static String al_app_cert_path;//支付宝公钥证书
    public static String al_alipay_cert_path;//支付宝公钥证书路径
    public static String al_alipay_root_cert_path;//支付宝根证书路径
    public static String al_alipay_notify_url;//支付宝支付回调地址
    public static String al_sign_type;//支付宝签名类型

    /**
     * 初始化支付宝配置文件
     */
    static {
        try {
            InputStream is = PayConfigUtils.class.getResourceAsStream("/payConfig.properties");
            Properties properties = new Properties();
            properties.load(is);
            appid = properties.getProperty("wx.appid");
            mch_id = properties.getProperty("wx.mch_id");
            notify_url = properties.getProperty("wx.notify_url");
            check_name = properties.getProperty("wx.check_name");
            api_key = properties.getProperty("wx.api_key");
            cert_path = properties.getProperty("wx.cert_path");

            al_appid = properties.getProperty("al.appid");
            al_app_cert_path = properties.getProperty("al.app_cert_path");
            al_alipay_cert_path = properties.getProperty("al.alipay_cert_path");
            al_alipay_root_cert_path = properties.getProperty("al.alipay_root_cert_path");
            al_alipay_notify_url = properties.getProperty("al.alipay_notify_url");
            al_sign_type = properties.getProperty("al.sign_type");
        } catch (Exception ex) {
            log.debug("加载配置文件：" + ex.getMessage());
        }
    }

    /**
     * 初始化微信配置文件
     */
    static {
        try {
            InputStream is = PayConfigUtils.class.getResourceAsStream("/payConfig.properties");
            Properties properties = new Properties();
            properties.load(is);
            appid = properties.getProperty("wx.appid");
            mch_id = properties.getProperty("wx.mch_id");
            notify_url = properties.getProperty("wx.notify_url");
            check_name = properties.getProperty("wx.check_name");
            api_key = properties.getProperty("wx.api_key");
            cert_path = properties.getProperty("wx.cert_path");
        } catch (Exception ex) {
            log.debug("加载配置文件：" + ex.getMessage());
        }
    }
}
